#include "pagelogin.h"
#include "ui_pagelogin.h"
#include <QDebug>

PageLogin::PageLogin(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::PageLogin)
{
    ui->setupUi(this);
    setAutoFillBackground(true);  //设置自动填充
    QPalette palette = BKGCLR;
    setPalette(palette);

    m_pNumKeyBoard = new NumberKeyBoard(this);
    m_pNumKeyBoard->move(650,270);
    connect(m_pNumKeyBoard,SIGNAL(setNumber(int)),this,SLOT(slotNumber(int)));
    connect(m_pNumKeyBoard,SIGNAL(backspace()),this,SLOT(slotbakspace()));
    connect(m_pNumKeyBoard,SIGNAL(cancel()),this,SLOT(slotClear()));
    connect(m_pNumKeyBoard,SIGNAL(ack()),this,SLOT(slotOK()));
}

PageLogin::~PageLogin()
{
    delete ui;
}

void PageLogin::slotNumber(int i)
{
    ui->lineEdit->setText(ui->lineEdit->text() + QString().setNum(i));
}

void PageLogin::slotClear()
{
    ui->lineEdit->setText("");
}

void PageLogin::slotbakspace()
{
    ui->lineEdit->setText(ui->lineEdit->text().left(ui->lineEdit->text().size()-1));
}

void PageLogin::slotOK()
{
    if(ui->lineEdit->text() == GlobalConfig::password)
    {
        emit loginOk();
        ui->lineEdit->setText("");
        ui->Error_Label->setText("");
        //Global::addOperationInfo(tr("登录维护界面"));
    }
    else
    {
        if(m_xErrorTimerBusy)
            return;
        ui->Error_Label->setText("密码错误");
        m_xErrorTimerBusy = true;
        QTimer::singleShot(3000,this,[=](){
            ui->Error_Label->setText("");
            m_xErrorTimerBusy = false;
        });
    }
}
